package operation;

import book.Book;
import book.BookList;

/**
 * @program: 11.19
 * @description:
 * @author: 李鑫月
 * @create: 2021-11-19 17:14
 **/
public class DelOperation implements IOperation {
    public void work(BookList bookList){
        System.out.println("删除图书");
        System.out.println("请输入你要删除的书籍：");
        String name=scanner.nextLine();
        int size=bookList.getUsedSize();
        int i = 0;
        for ( ;i <size; i++) {
            Book book=bookList.getPos(i);
            if(name.equals(book.getName())){
                break;
            }
        }
        if(i<size){
            for (int j = i; j <size-1 ; j++) {
                Book book2=bookList.getPos(j+1);
                bookList.setBook(j,book2);
            }
            bookList.setUsedSize(size-1);
            bookList.setBook(size,null);
            System.out.println("删除成功");
        }
        else {
            System.out.println("没有这本书");

        }
    }
}
